using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

using Ssb.Logic;

namespace Ssb
{
    public partial class Fighter
        : DrawableGameComponent
    {
        #region FighterAnimations
            #region Attacks
                #region Jabs
                    public FighterAnimation Attack1;
                    public FighterAnimation Attack2;
                    public FighterAnimation Attack3;
                #endregion

                #region Tilts
                    public FighterAnimation AttackS3Hi;
                    public FighterAnimation AttackS3S;
                    public FighterAnimation AttackS3Lw;
                #endregion

                #region Smashes
                    public FighterAnimation AttackS4Hi;
                    public FighterAnimation AttackS4S;
                    public FighterAnimation AttackS4Lw;
                #endregion

                #region SmashCharges
                    public FighterAnimation AttackSC4Hi;
                    public FighterAnimation AttackSC4S;
                    public FighterAnimation AttackSC4Lw;
                #endregion

                #region Aerials
                    public FighterAnimation AttackAirF;
                    public FighterAnimation AttackAirB;
                    public FighterAnimation AttackAirHi;
                    public FighterAnimation AttackAirLw;
                #endregion

                #region Grabs
                    public FighterAnimation AttackGrabN;
                    public FighterAnimation AttackGrabHi;
                    public FighterAnimation AttackGrabF;
                    public FighterAnimation AttackGrabB;
                    public FighterAnimation AttackGrabLw;
                #endregion  

                #region Specials
                    public FighterAnimation SpecialS;
                    public FighterAnimation SpecialHi;
                    public FighterAnimation SpecialLw;
                    public FighterAnimation SpecialN;
                #endregion

                public FighterAnimation DashAttack;
            #endregion

            #region Miscs
                    #region Idle
                    public FighterAnimation IdleMain;
                    public FighterAnimation Idle1;
                    public FighterAnimation Idle2;
                    public FighterAnimation Idle3;
                #endregion

                #region Movement
                    public FighterAnimation Falling;
                    public FighterAnimation Walking;
                    public FighterAnimation Running;
                    public FighterAnimation Jumping;
                #endregion

                #region Random
                    public FighterAnimation Clinging;
                    public FighterAnimation Crouching;
                    public FighterAnimation Grab;
                #endregion
            #endregion

            public FighterAnimation AttackDash;
        #endregion

        #region FighterProperties

        public bool isAirborne;

        /// <summary>
        /// The global velocity of the fighter
        /// </summary>
        public Vector2 GlobalVelocity;

        /// <summary>
        /// The Maximum speed attainable by running
        /// </summary>
        public float MaxRunningVelocity;

        /// <summary>
        /// The initial speed at which the fighter runs
        /// </summary>
        public float InitialRunningSpeed;

        /// <summary>
        /// The acceleration of the fighter's running
        /// </summary>
        public float RunSpeedAccel;

        public float JumpVelocity;
        public float JumpVeloDegen;
        public float MaxFallSpeed;

        #endregion

        public float Left { get { return this.GetCurrentFrame().X; } }
        public float Right { get { return this.GetCurrentFrame().X + GetCurrentFrame().texture.Width; } }
        public float Top { get { return this.GetCurrentFrame().Y; } }
        public float Bottom { get { return this.GetCurrentFrame().Y + GetCurrentFrame().texture.Height; } }

        public Fighter(Game game)
            : base(game)
        {
            isIntangible = false;
            CurrentAnimation = FighterAnimationType.IdleMain;
        }

        /// <summary>
        /// The Fighter's character select screen image
        /// </summary>
        public Image CSSImage;

        /// <summary>
        /// The only animation that is drawn/updated by the game
        /// </summary>
        public FighterAnimationType CurrentAnimation {get;protected set;}

        public bool isIntangible { get; protected set; } // Is the player tangible (false), or intangible (true)
        public bool isClinging { get; protected set; } // Is hanging onto the stage
        public bool isHuman { get; protected set; } // Receives input via PlayerInputHandler

        /// <summary>
        /// Switches the current animation to the desired one.
        /// </summary>
        /// <param name="anim">The animation to switch to.</param>
        public void ChangeAnimation(FighterAnimationType anim)
        {
            FighterAnimationMap[CurrentAnimation].Disable();
            CurrentAnimation = anim;
            FighterAnimationMap[CurrentAnimation].Enable();
        }

        /// <summary>
        /// Physics. Checks if the fighter collides with the given bubble.
        /// </summary>
        /// <param name="bub">The bubble to test</param>
        /// <returns>Whether or not the fighter collides with the bubble.</returns>
        public bool CollidesWithBubble(Bubble bub)
        {
            Image cframe = GetCurrentFrame();

            Vector2 topright = new Vector2(cframe.X + cframe.texture.Width, cframe.Y);
            Vector2 bottomleft = new Vector2(cframe.X, cframe.Y + cframe.texture.Height);
            Vector2 bottomright = new Vector2(cframe.X + cframe.texture.Width, cframe.Y + cframe.texture.Height);

            return (bub.isPointInside(cframe.Coords) && bub.isPointInside(topright) && bub.isPointInside(bottomleft) && bub.isPointInside(bottomright));
        }

        

        

        public void MakeIntangible()
        {
            isIntangible = true;
        }

        public void MakeTangible()
        {
            isIntangible = false;
        }

        public override void Update(GameTime gt)
        {
            FighterAnimationMap[CurrentAnimation].Update(gt);

            if (!isHuman)
                return;


        }

        public override void Draw(GameTime gt)
        {
            FighterAnimationMap[CurrentAnimation].Draw(gt);
        }
    }
}
